home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / cfuncs.zip / SCREEN.C < prev    next >
Text File  |  1991-08-07  |  3KB  |  131 lines

  1.  
  2. #include <dos.h>
  3.  
  4. char far *VIDEO_BASE = 0;
  5.  
  6. void dma_init(int mode);
  7. void SaveScrn (int, int, int, int, char *);
  8. void RestScrn (int, int, int, int, char *);
  9. void dma_init(int video_mode)
  10. {
  11.  
  12.     if (video_mode == 7)
  13.  
  14.                 VIDEO_BASE = (char far *) 0xb0000000;
  15.         else
  16.                 VIDEO_BASE = (char far *) 0xb8000000;
  17. }
  18.  
  19. void dma_puts (int x, int y, int attr, char *pointer)
  20. {
  21.         char far *current_pos;
  22.  
  23.     if(!VIDEO_BASE)
  24.         dma_init(video_mode());
  25.  
  26.     current_pos = VIDEO_BASE + (y-1)*160 + (x-1)*2;
  27.  
  28.     while ( *pointer  != '\0' )
  29.         {
  30.                 *current_pos++ = *pointer++;
  31.                 *current_pos++ = (char) attr;
  32.         }
  33. }
  34.  
  35.  
  36. void SaveScrn (x, y, width, length, buffer)
  37. int x, y, width, length;
  38. char *buffer;
  39. {
  40.  
  41.         char x1, y1;
  42.         char far *current_pos;
  43.     width += --x;
  44.     length += --y;
  45.  
  46.     if(!VIDEO_BASE)
  47.         dma_init(video_mode());
  48.  
  49.     for ( y1= y; y1 < length ; y1++ )
  50.         {
  51.                 current_pos = VIDEO_BASE + (y1*160) + x*2;
  52.         for ( x1 = x; x1 < width; x1++ )
  53.                 {
  54.                         *buffer++ = *current_pos ++;
  55.                         *buffer++ = *current_pos ++;
  56.                 }
  57.         }
  58. }
  59.  
  60. void RestScrn (x, y, width, length, buffer)
  61. int x, y, width, length;
  62. char *buffer;
  63. {
  64.  
  65.         char x1, y1;
  66.         char far *current_pos;
  67.     width += --x;
  68.     length += --y;
  69.  
  70.     if(!VIDEO_BASE)
  71.         dma_init(video_mode());
  72.  
  73.     for ( y1= y; y1 < length ; y1++ )
  74.         {
  75.                 current_pos = VIDEO_BASE + (y1*160) + x*2;
  76.         for ( x1 = x; x1 < width; x1++ )
  77.                 {
  78.                         *current_pos ++ = *buffer++;
  79.                         *current_pos ++ = *buffer++;
  80.                 }
  81.          }
  82. }
  83.  
  84. /*------------------------NewClear--------------------------*/
  85. /*DESCRIPTION: Clears the screen by filling it with ▒ chars.*/
  86. /*                                */
  87. /*INPUT: foreground - color of foreground in design        */
  88. /*       backgound - color of backgound in design        */
  89. /*USES: nothing                            */
  90. /*----------------------------------------------------------*/
  91.  
  92. void NewClear(int foreground, int background)
  93. {
  94.     char far *current_pos;
  95.     char fillchar = '▒';
  96.     unsigned short    attr, i;
  97.  
  98.     if(!VIDEO_BASE)
  99.         dma_init(video_mode());
  100.  
  101.     current_pos = VIDEO_BASE;
  102.  
  103.     attr = foreground + (background << 4);
  104.  
  105.     for(i = 0; i<2000; ++i)
  106.     {
  107.         *current_pos++ = fillchar;
  108.         *current_pos++ = attr;
  109.     }
  110. }
  111.  
  112. int video_mode (void)
  113. {
  114.     union REGS r;
  115.     r.h.ah = 15;
  116.     return ( int86(0x10, &r, &r) & 255 );
  117. }
  118.  
  119. /* main()
  120. {
  121.     char buff[500];
  122.  
  123.     NewClear(1, 7);
  124.     dma_puts(5, 5, 1, "hello");
  125.     SaveScrn(1, 2, 10, 10, buff);
  126.     dma_puts(2, 3, 1, "hi there");
  127.     RestScrn(1, 2, 10, 10, buff);
  128.  
  129. } */
  130.  
  131.